/*-----Control Type Function */
function showControlTypeSearch() {
	window.location.href="showControlTypeSearch.do";
}

function findControlTypeSearchList(pageIndex) {
	$.ajax({
		type:"post",
		url: "ajaxControlTypeSearchList.do",
		data:{strParam1:$("#txtCTName").val(),strParam2:$("#txtCTDesc").val(),pageIndex:pageIndex,orderBy:"id"},
		success:function(msg){
			$("#listControlTypeBox").html(msg);
		}
	});
}

function showControlTypeEdit(){
	$("#controlTypeId").val($("#listControlType tbody input:checked").val());
	$("#fmControlType").attr("action","showControlTypeEdit.do");
	$("#fmControlType").submit();
}

function saveControlType(){
	$("#frmCTEdit").submit();
}

function deleteControlTypeById() {
    var controlTypeIds="";
    $("#listControlType tbody input:checked").each(function(){ 
        controlTypeIds += $(this).val()+","
    });
    var sltCT = $("#listControlType tbody input:checked").length
    if (sltCT > 0) {
	    showMessageDialog("删除布控类型","确定要删除所选“"+sltCT+"”条布控类型记录吗？",
	    	function () {
				$.ajax({
					type:"post",
					url:"ajaxDeleteControlTypeById.do",
					data:{controlTypeIds:controlTypeIds.substring(0, controlTypeIds.length-1)},
					success:function(msg){
						findControlTypeSearchList(0);
					}
				});}
		    ,dialogType.warning);
    } 
}

function showControlTypeView(){
	$("#controlTypeId").val($("#listControlType tbody input:checked").val());
	$("#fmControlType").attr("action","showControlTypeView.do");
	$("#fmControlType").submit();
}

/*-----Control Vehicle Function */
function showControlVehicleSearch() {
	window.location.href="showControlVehicleSearch.do";
}

function findControlVehicleSearchList(pageIndex) {
	$.ajax({
		type:"post",
		url: "ajaxControlVehicleSearchList.do",
		data:{strParam1:$("#txtHPHM").val(),strParam2:$("#sltBKLX").val(),
			  strDateBegin:$("#strBeginTime").val(),strParam3:$("#sltHPZL").val(),
			  strParam4:$("#sltCLLX").val(),strDateEnd:$("#strEndTime").val(),
			  strDateBegin1:$("#strBeginTime1").val(),strDateEnd1:$("#strEndTime1").val(),
			  pageIndex:pageIndex,orderBy:"id"},
		success:function(msg){
			$("#listControlVehicleBox").html(msg);
		}
	});
}
function showControlVehicleEdit(){
	$("#controlVehicleId").val($("#VehicleInfoTable tbody input:checked").val());
	$("#fmControlVehicle").attr("action","showControlVehicleEdit.do");
	$("#fmControlVehicle").submit();
}
function saveControlVehicle(){	
	var i = 0;
	$("#ControlTasksTable tbody input[type='hidden']").each(
			function () {$(this).attr("name","listControlTask["+ i++ +"].id");}
	);
	$("#frmCVEdit").submit();
}
function deleteControlVehicleById() {
    var controlVehicleIds="";
    $("#VehicleInfoTable tbody input:checked").each(function(){ 
        controlVehicleIds += $(this).val()+","
    });
    var sltCV = $("#VehicleInfoTable tbody input:checked").length
    if (sltCV > 0) {
	    showMessageDialog("删除布控车辆","确定要删除所选“"+sltCV+"”条布控车辆记录吗？",
	    	function () {
				$.ajax({					
					type:"post",
					url:"ajaxDeleteControlVehicleByIds.do",
					data:{controlVehicleIds:controlVehicleIds.substring(0, controlVehicleIds.length-1)},
					success:function(msg){
						findControlVehicleSearchList(0);
					}
				});}
		    ,dialogType.warning);
    } 
}

function showControlVehicleView(){
	$("#controlVehicleId").val($("#VehicleInfoTable tbody input:checked").val());
	$("#fmControlVehicle").attr("action","showControlVehicleView.do");
	$("#fmControlVehicle").submit();
}


/*-----Control Task Function */
function showControlTaskSearch(){
	window.location.href="showControlTaskSearch.do";
}

function findControlTaskSearchList(pageIndex){
	$.ajax({
		type:"post",
		url:"ajaxControlTaskSearchList.do",
		data:{strParam1:$("#txtCTaskName").val(),strParam2:$("#sltIsUse").val(),strDateBegin:$("#strDateBegin").val(),strDateBegin1:$("#strDateBegin1").val(),
			strDateEnd:$("#strDateEnd").val(),strDateEnd1:$("#strDateEnd1").val(),pageIndex:pageIndex,orderBy:"id"},
		success:function(msg){
			$("#listControlTaskBox").html(msg);
		}
	});
}
function showControlTaskEdit(){
	if($("#listControlTask tbody input:checked").length == 0)
	{
		alert("请选择一行");
		return;
	}
	$("#controlTaskId").val($("#listControlTask tbody input:checked").val());
	$("#fmControlTask").attr("action","showControlTaskEdit.do");
	$("#fmControlTask").submit();
}

function saveControlTask(){
	if($("#txtCTaskName").val() == "")
	{
		$("#informDiv").html("布控任务名称不能为空！");
		$("#txtCTaskName").focus();
		return;
	}
	if($("#strDateBegin").val() == "")
	{
		$("#informDiv").html("任务生效时间不能为空！");
		return;
	}
	if($("#strDateEnd").val() == "")
	{
		$("#informDiv").html("任务过期时间不能为空！");
		return;
	}
	var i = 0;
	$("#controlPoints tbody input[type='hidden']").each(function () {$(this).attr("name","listControlPoint["+ i++ +"].id");});
	i = 0;
	$("#controlVehicles tbody input[type='hidden']").each(function () {$(this).attr("name","listControlVehicle["+ i++ +"].id");});
	i = 0;
	$("#InformRules tbody input[type='hidden']").each(function () {$(this).attr("name","listInformRule["+ i++ +"].id");});
	$("#frmCTaskEdit").submit();
}

function deleteControlTaskById() {
    var controlTaskIds="";
    $("#listControlTask tbody input:checked").each(function(){ 
    	controlTaskIds += $(this).val()+","
    });
    var sltCT = $("#listControlTask tbody input:checked").length;
    if (sltCT == 0)
    {
    	alert("请选择一行或多行");
    	return;
    }
    showMessageDialog("删除布控类型","确定要删除所选"+sltCT+"条布控任务记录吗？",
	    	function () {
				$.ajax({
					type:"post",
					url:"ajaxDeleteControlTaskByIds.do",
					data:{controlTaskIds:controlTaskIds.substring(0, controlTaskIds.length-1)},
					success:function(msg){
						findControlTaskSearchList(0);
					}
				});}
		    ,dialogType.warning);
}
function showControlTaskView(){
	if($("#listControlTask tbody input:checked").length == 0)
	{
		alert("请选择一行");
		return;
	}
	$("#controlTaskId").val($("#listControlTask tbody input:checked").val());
	$("#fmControlTask").attr("action","showControlTaskView.do");
	$("#fmControlTask").submit();
}
function updateUseControlTaskState(isUse){
	 var controlTaskIds="";
	    $("#listControlTask tbody input:checked").each(function(){ 
	    	controlTaskIds += $(this).val()+","
	    });
	    var sltCT = $("#listControlTask tbody input:checked").length
	    if (sltCT > 0) {
	    	$.ajax({
				type:"post",
				url:"ajaxUseControlTaskState.do",
				data:{controlTaskIds:controlTaskIds.substring(0, controlTaskIds.length-1),isUsing:isUse},
				success:function(msg){
					findControlTaskSearchList(0);
				}
	    	});
	    }
}